package Sequence;

import java.util.ArrayDeque;

public class Test0513 {
}

class Solution0513_1 {
    public int findBottomLeftValue(TreeNode root) {
        int ans=0;
        ArrayDeque<TreeNode> treeNodes = new ArrayDeque<>();
        treeNodes.push(root);
        int size = treeNodes.size();
        while ((size=treeNodes.size())>0) {
            ans=treeNodes.peek().val;
            for (int i = 0; i < size; i++) {
                TreeNode poll = treeNodes.poll();
                if(poll.left!=null){
                    treeNodes.offer(poll.left);
                }
                if(poll.right!=null){
                    treeNodes.offer(poll.right);
                }
            }
        }

        return ans;
    }

}
